Skip to content

Recommend PKCE and deprecate the client secret - #974

Merged
kevincador merged 3 commits into
masterfrom
feat/pkce
Oct 2, 2026
Merged

kevincador merged 3 commits into
masterfrom
feat/pkce

Conversation

@kevincador

@kevincador kevincador commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes PKCE the recommended way to sign users in to Trakt, and starts phasing out the Client Secret for anything but server-to-server calls. With PKCE as the default, a copied Client ID can no longer be turned into tokens.

API reference (@trakt/api)

  • Document the PKCE parameters: code_challenge and code_challenge_method on authorize, and code_verifier on token.
  • client_secret is now optional and marked deprecated on every /oauth body (token, refresh, device token, revoke), from one shared schema.
  • Authorization Code Flow endpoint descriptions point to the PKCE guide, and client_secret is removed from request tables.

Developer portal

  • New guide at /docs/pkce: why PKCE, the authorization code and device code flows, and redirect URI rules. Linked from Authentication and Create an App.
  • App page: PKCE recommendation next to the Client Secret, which is now labelled deprecated. When the API stops returning a secret, the page shows a "not issued" placeholder instead of an empty value.
  • App page and app form: a prominent warning when a redirect URI is not a public https:// address (custom schemes, http://, localhost, out-of-band). Mobile apps are pointed to Universal Links and verified App Links. It warns but does not block saving.
  • Request body samples leave out deprecated fields, so client_secret no longer appears in the /oauth samples.
  • Fix: the apps page no longer returns a 500 in local dev when PUBLIC_GITHUB_CLIENT_ID is not set. Connect GitHub is disabled with a note instead. The ID is now read from the dynamic public env, which the static build writes to /_app/env.js. @vladjerca feel free to revert that commit, I just needed that to test locally 👨‍🔬

Notes for reviewers

  • Existing apps that use custom-scheme or localhost redirects will start seeing the warning. This is intended.
  • The @trakt/api change needs a version tag to publish.

Test plan

  • deno task check, deno task test (325 passing), deno task build, and both format checks in projects/developer
  • deno fmt --check, deno lint, and deno task publish:check in projects/api
  • deno task openapi:validate
  • /docs/pkce renders and shows in the sidebar
  • The postOauthToken sample body has no client_secret, and the note renders on the /oauth endpoints
  • /apps loads without PUBLIC_GITHUB_CLIENT_ID
  • App detail page with and without a secret, and with an insecure redirect URI (needs a signed-in account with GitHub linked)
  • App form shows the warning live while typing an insecure redirect URI

Local testing screenshots

Screenshot 2026-10-02 at 09 11 44 Screenshot 2026-10-02 at 09 11 31

@kevincador
kevincador requested a review from vladjerca October 2, 2026 07:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T07:56:41.829248Z d785eb7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2c8322e5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread projects/developer/src/lib/features/apps/PkceNotice.svelte Outdated
Comment thread projects/api/src/contracts/oauth/schema/request/codeRequestSchema.ts Outdated
Comment thread projects/developer/src/lib/features/apps/unsafeRedirectUris.ts Outdated
@kevincador

Copy link
Copy Markdown
Contributor Author

Addressed all three Codex points, each folded into its origin commit:

  • P1 bare element selectors in the notices: child classes, in a9ecedb.
  • P2 code_challenge_method: restricted to the S256 literal, in 8b40e92.
  • P2 private-network redirect hosts: private and link-local IPv4/IPv6 and .local now flagged, in a9ecedb.

Pushed as d785eb7. Portal check, 335 tests, and build green; api lint and publish dry run green; OpenAPI validates.

@kevincador

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d785eb7b64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread projects/api/src/contracts/oauth/schema/request/codeRequestSchema.ts Outdated

@vladjerca vladjerca left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted in error.

@vladjerca
vladjerca dismissed their stale review October 2, 2026 10:38

Posted in error.

PKCE is now the recommended way to sign users in, and the Client Secret
is deprecated for anything but server-to-server calls.

- Add code_challenge and code_challenge_method to the authorize and
  device code requests, and code_verifier to the token and device token
  requests.
- Make client_secret optional and deprecated on every /oauth body
  (token, refresh, device token, revoke), from one shared schema.
- Add a note to every /oauth endpoint description pointing to the PKCE
  guide, and drop client_secret from the request tables.
Enforcing PKCE as the default makes a copied Client ID useless, so the
portal now steers developers to it.

- Add a PKCE guide at /docs/pkce, covering both the authorization code
  and device code flows, and link it from Authentication and Create an
  App.
- Show a PKCE recommendation next to the Client Secret on the app page
  and mark the secret deprecated. When the API stops returning a
  secret, show a placeholder instead of an empty value.
- Warn on the app page and in the app form when a redirect URI is not a
  public https:// address (custom schemes, http, localhost, out-of-band).
- Leave deprecated fields out of generated request body samples, so
  client_secret no longer appears in the /oauth samples.
A missing PUBLIC_GITHUB_CLIENT_ID made the static env import fail, so
the apps page returned a 500 in local dev. Read it from the dynamic
public env instead, and disable the Connect GitHub buttons with a note
when it is not set.

@vladjerca vladjerca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated the corrected OAuth contract and developer documentation: OpenAPI validation, API lint and publish dry run, plus developer formatting, type-check, build, and 335 tests all pass. The public documentation now matches the supported flows.

Reset your local branch before pushing again.

@kevincador
kevincador merged commit 4d57274 into master Oct 2, 2026
5 checks passed
@kevincador
kevincador deleted the feat/pkce branch October 2, 2026 11:35
bobsupra pushed a commit to bobsupra/NuvioTVOS that referenced this pull request Oct 8, 2026
…optional

Trakt deprecated the client secret on 2026-10-01 (trakt/trakt-api#974): apps
created since then are PKCE-only and have no secret, and `client_secret` is
now optional/deprecated on every /oauth body. The device flow still works for
these apps — you just omit `client_secret` (the device_code is the proof of
possession). PKCE itself isn't used by the device flow; it only exists in the
authorization-code flow.

Without this, a PKCE-only Client ID can't connect: isConfigured() required a
secret and the token/refresh/revoke calls always sent one, which Trakt rejects.

- client_secret is now optional on device/token, token refresh, and revoke
  (sent only when the app still has one, so legacy apps keep working).
- isConfigured() requires only a Client ID.
- OAuth requests target auth.trakt.tv per current Trakt docs; the data API
  stays on api.trakt.tv.
- Settings: the Client Secret field is marked optional and no longer gates
  "Connect".

Adds TraktPkceAuthTests covering the secret-less device-token/refresh request
bodies, legacy-secret backward-compat, isConfigured, and the OAuth host.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bendrucker added a commit to bendrucker/logbook that referenced this pull request Oct 19, 2026
<!-- claude-projects-attribution: {"github_login":"bendrucker"} -->
_Requested by **Ben** · [project
thread](https://claude.ai/code/project/chan_01TWyQ8yB7mqhkPt3YqS4rif?thread=cmsg_01TWyQ8yB7mqhkPt3YqS4rif5Weg2UHc3iexFshwczPTxF)_

Before: the pipeline and the monitor read Trakt with only the client ID.
The first request of many hours drew a 429 with a `Retry-After` of up to
260s, even though the hub sends only two or three requests an hour.
After a 429, history and ratings stopped until the next hour, and the
monitor's Trakt probe failed.

After: both read Trakt as the account through OAuth, each with its own
Trakt application and grant. Trakt has no personal access token, so each
one links once through Trakt's device flow. Until a grant is stored, the
pipeline records `skip.missing_secret` for both Trakt kinds and the
nightly re-walk, and the monitor leaves Trakt out of its probe. Neither
Worker uses a client secret. Trakt deprecated them in favor of PKCE
([trakt-api#974](trakt/trakt-api#974)), and the
device and refresh calls send the client ID alone.

How, pipeline: `src/trakt/auth.ts` resolves the token once per
invocation from D1's `trakt_tokens`. It refreshes once six hours or less
remain on Trakt's 24-hour token. The grant lives in D1 rather than KV
because Trakt rotates the refresh token on every refresh, and an
eventually consistent read of a rotated token would be a dead
credential. Rotation drives the rest of the design:

- A refresh writes only over the row it read. If Trakt refuses a refresh
token that a concurrent invocation already spent (`invalid_grant`), the
losing invocation re-reads the row, immediately and again two seconds
later, to pick up the winner's token.
- Any refusal or failure before Trakt issues a grant falls back to the
token in hand while it has time left. Once that token lapses, the error
says what to fix. `invalid_grant` means re-run the login. Any other
refusal means the client ID and redirect URI don't match the Trakt
application.
- Once Trakt issues a grant, the old refresh token is spent. The D1
write retries. If it still fails, the invocation keeps the new token
rather than dropping it.
- A 429 from the token endpoint is a rate-limit stop with `resumeAt`.
Token endpoint failures carry `endpoint: "oauth"`, which keeps their
bodies out of R2, where only data pages are archived.

The device-flow routes are `POST /admin/trakt/login`, and
`/admin/trakt/login/poll` with `device_code` in a JSON body. They
exchange the code inside the Worker, so the grant never leaves it, and
the code never appears in a URL. Without a client secret, the code plus
the public client ID is enough to claim the grant. A refresh repeats
`TRAKT_REDIRECT_URI` (`https://bendrucker.me/`), which must be
registered on the app. A 429's message now names the limit from
`X-Ratelimit`, or says the header was missing.

How, monitor: `workers/monitor/src/trakt-auth.ts` is a trimmed copy of
the refresh logic with the same fallback and write retry. It has no
concurrency guard, since the monitor runs once an hour on its own. The
token resolves once per run, on first use. A D1 failure reading the
grant leaves Trakt out of the probe rather than failing the run. The
monitor has no admin surface, so `bun run monitor:trakt-login` runs the
device flow locally with the monitor's client ID. It writes the grant to
the monitor's D1 through a temporary file passed to `wrangler d1 execute
--remote`.

Setup after merge:

1. Register `https://bendrucker.me/` as a redirect URI on both Trakt
apps and remove `urn:ietf:wg:oauth:2.0:oob`.
2. Link each app:

```sh
ADMIN_TOKEN=... bun run trakt:login https://<worker-host>
bun run monitor:trakt-login
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01PjhteXVmB2DedotVunbH21

---------

Co-authored-by: Claude <noreply@anthropic.com>
halgurdh added a commit to halgurdh/free-my-tv-smarttube-stremio that referenced this pull request Oct 25, 2026
…hed and bring in your watchlist

Signing in is Trakt's device code with PKCE: only the Client ID is needed, since Trakt no longer issues a client
secret to new apps (trakt/trakt-api#974). A secret from an older app is still sent.
Titles from Trakt show only when one of the TV's apps has them, like TMDB's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
halgurdh added a commit to halgurdh/free-my-tv-smarttube-stremio that referenced this pull request Oct 25, 2026
…hed and bring in your watchlist

Signing in is Trakt's device code with PKCE: only the Client ID is needed, since Trakt no longer issues a client
secret to new apps (trakt/trakt-api#974). A secret from an older app is still sent.
Titles from Trakt show only when one of the TV's apps has them, like TMDB's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants